
import os 

fil_protocol = \
{'protocol.py':'/media/lhpc04/da8a185a-95f0-4cbd-ba0a-5fe144872bd7/worksapce/code/test/python/remote_cmd/3dparts/ipmsg/src/ipmsg.h',
'resource.py':'/media/lhpc04/da8a185a-95f0-4cbd-ba0a-5fe144872bd7/worksapce/code/test/python/remote_cmd/3dparts/ipmsg/src/resource.h'}


define = '#define'
undel = []

for f in fil_protocol:
    if os.path.exists(f):
        continue
    df = open(f, 'w')
    with open(fil_protocol[f]) as fr:
        for i,l in enumerate(fr.readlines()):
            l =  l.strip()
            if l[:len(define)] == define:
                d = l[len(define):].lstrip()
                dci = d.find('//')
                if dci >= 0:
                    d = d[:dci]
                if d.find('(') >= 0:
                    undel.append([i,l])
                    # print(d)
                else:
                    ds = d.split()
                    if len(ds) == 2:
                        print(ds[0]+ ' = '+ ds[1].replace('"','\''))
                        df.write(ds[0]+ ' = '+ ds[1].replace('"','\'').rstrip('UL')+'\n')
    print('\n\n---- undeal data -----')
    for d in undel:
        print(d)
    df.close()
# print(undel)